package com.bwstudio.demo.provider.service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

import org.apache.dubbo.config.annotation.Service;

import com.bwstudio.demo.provider.api.DelaySimulateService;

// dubbo访问超时重试，设置retries=0无效的时候，可以尝试设为-1
@Service
public class DelaySimulateServiceImpl implements DelaySimulateService {

	private void sleep(long ms) {
		try {
			TimeUnit.MILLISECONDS.sleep(ms);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public String delay(long ms) {
		sleep(ms);
		return "delay ------";
	}

	@Override
	public CompletableFuture<String> asyncDelay(long ms) {
		sleep(ms);
		CompletableFuture<String> future = 
				CompletableFuture.completedFuture("asyncDelay ------");
		return future;
	}

}
